import { GCellRenderer } from "../../../../com/mui/controls/GCellRenderer";
import { DomWarInfo } from "./DomWarInfo";
import { ObjCreate } from "../common/ObjCreate";
import { ResFileConst } from "../../resource/ResFileConst";
import { MsgManager } from "../../manager/MsgManager";
import { Language } from "../../../../extend/language/Language";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { ProxyConfig } from "../../resource/ProxyConfig";
import { FilterConst } from "../../../component/gconst/FilterConst";
import { GLoadedButton } from "../../../../com/mui/controls/GLoadedButton";
import { GTextFiled } from "../../../../com/mui/controls/GTextFiled";
import { DominionWarCopyInfoPanel } from "../copy/dominionWar/DominionWarCopyInfoPanel";
//class DomWarEnterCellRenderer
    
    export  class DomWarEnterCellRenderer extends GCellRenderer
    {
        constructor()
        {
            super();
            this.initUI();
            return;
        }

        /* internal  */get warInfo(): DomWarInfo
        {
            return this._data as DomWarInfo;
        }

        /* internal  */initUI(): void
        {
            this.buttonMode = true;
            this._enterBtn = ObjCreate.createGLoadedButton(ResFileConst.DominionWarEnterBtn, 0, 0, 142, 142, this);
            this._serverTxt = ObjCreate.createGTextField("", 20, 20, 100, 25, this);
            this._serverTxt.autoSize = "center";
            this._serverTxt.mouseEnabled = false;
            this._servProxyNameTxt = ObjCreate.createGTextField("", 20, 55, 100, 25, this);
            this._servProxyNameTxt.autoSize = "center";
            this._servProxyNameTxt.mouseEnabled = false;
            this._peopleCapTxt = ObjCreate.createGTextField("", 56, 95, 100, 25, this);
            this._servProxyNameTxt.autoSize = "center";
            this._servProxyNameTxt.mouseEnabled = false;
            this.addEventListener(flash.events.MouseEvent.CLICK, this.onClickhandler);
            return;
        }

        protected onClickhandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this.warInfo) 
            {
                if (this.warInfo.isMaxNum) 
                {
                    MsgManager.showRollTipsMsg(Language.getString(90614));
                }
                else 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.ToEnterDomWarCopy, this.warInfo));
                }
            }
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            var loc1=null;
            var loc2=false;
            if (arg1 == null || _data == arg1) 
            {
                return;
            }
            super.data = arg1;
            if (this.warInfo) 
            {
                loc1 = ProxyConfig.instance.getProxyName(this.warInfo.dominionId.proxyId);
                this._serverTxt.text = "[" + loc1 + "_" + this.warInfo.dominionId.serverId + "]";
                this._servProxyNameTxt.text = loc1;
                this._peopleCapTxt.text = "(" + this.warInfo.peopleNum + "/" + this.warInfo.getMaxNum() + ")";
                loc2 = !this.warInfo.isMaxNum;
                this.setEnable(loc2);
            }
            return;
        }

        /* internal  */setEnable(arg1: Boolean): void
        {
            if (arg1) 
            {
                this.filters = [];
                this.mouseChildren = arg1;
                this.mouseEnabled = arg1;
            }
            else 
            {
                this.filters = [FilterConst.colorFilter2];
                this.mouseChildren = arg1;
                this.mouseEnabled = arg1;
            }
            return;
        }

        /* internal */ /* var */_enterBtn: GLoadedButton;

        /* internal */ /* var */_serverTxt: GTextFiled;

        /* internal */ /* var */_servProxyNameTxt: GTextFiled;

        /* internal */ /* var */_peopleCapTxt: GTextFiled;

        /* internal */ /* var */infoPanel: DominionWarCopyInfoPanel;
    }
